package model

import (
	"fmt"
	"strings"
)

// TypeError 转换 DataUserModel 时的错误
type SimpleError struct {
	Name string	 // 错误类型的名称
	Desc string	// 错误描述
}

func NewTypeError(name string) *SimpleError {
	return &SimpleError{
		Name: name,
		Desc: "type error.",
	}
}

func NotFoundError(name string) *SimpleError {
	return &SimpleError{
		Name: name,
		Desc: "is not found.",
	}
}

func (s *SimpleError) Error() string {
	if len(s.Name) < 1 {
		return fmt.Sprintf("%s %s", strings.ToUpper(s.Name), s.Desc)
	}
	upper := strings.ToUpper(s.Name[:1])
	return fmt.Sprintf("%s%s %s.", upper, s.Name[1:], s.Desc)
}